{% extends 'base/cms_base.html' %}

{% block title %}
    发布文章
{% endblock %}

{% block head %}
    <script src="{% static 'ueditor/ueditor.config.js' %}"></script>
    <script src="{% static 'ueditor/ueditor.all.min.js' %}"></script>
    <script src="{% static 'js/write_article.min.js' %}"></script>
{% endblock %}

{% block content-header %}
     <h1>
    {% if article %}
        编辑文章
    {% else %}
        发布文章
    {% endif %}
    </h1>
{% endblock %}

{% block content %}
    <div class="row">
        <div class="col-md-12">
            <div class="box box-primary">
                <form action="#" method="post" class="form">
                    <div class="box-body">
                        <div class="form-group">
                            <label for="title-form">标题</label>
                            {% if article %}
                                <input type="text" class="form-control" name="title" id="title-form" value="{{ article.title }}">
                            {% else %}
                                <input type="text" class="form-control" name="title" id="title-form">
                            {% endif %}
                        </div>
                        <div class="form-group">
                            <label for="category-form">分类</label>
                            <select id="category-form" name="category" class="form-control">
                                {% for category in categories %}
                                    {% if article and article.category_id == category.pk %}
                                        <option value="{{ category.pk }}" selected>{{ category.name }}</option>
                                    {% else %}
                                        <option value="{{ category.pk }}">{{ category.name }}</option>
                                    {% endif %}
                                {% endfor %}

                            </select>
                        </div>
                        <div class="form-group">
                            <label for="desc-form">描述</label>
                            {% if article %}
                                <input type="text" class="form-control" id="desc-form" name="desc" value="{{ article.desc }}">
                            {% else %}
                                <input type="text" class="form-control" id="desc-form" name="desc">
                            {% endif %}
                        </div>
                        <div class="form-group">
                            <label for="thumbnail-form">缩略图</label>
                            <div class="input-group">
                                {% if article %}
                                    <input type="text" class="form-control" id="thumbnail-form" name="thumbnail" value="{{ article.thumbnail }}">
                                {% else %}
                                    <input type="text" class="form-control" id="thumbnail-form" name="thumbnail">
                                {% endif %}
                                <span class="input-group-btn">
                                    <label for="upload-img-btn" class="btn btn-default bnt-file">
                                        上传图片
                                        <input style="display: none" type="file" id="upload-img-btn"/>
                                    </label>
                                </span>
                            </div>
                        </div>
                        <div class="form-group">
                            <label for="editor">内容</label>
                            <script id="editor" type="text/plain">
                                {{ article.content|safe }}
                            </script>
                        </div>
                    </div>
                    <div class="box-footer">
                        <button id="submit-btn" data-article-id="{{ article.pk }}" class="btn btn-primary pull-right">发布</button>
                    </div>
                </form>
            </div>
        </div>
{% endblock %}
